﻿Imports System.ComponentModel

Namespace ViewModel

    Public Class FontDialogWindowViewModel
        Inherits ViewModelBase

        'Private _fontFamilies As ICollection(Of System.Windows.Media.FontFamily) = Fonts.SystemFontFamilies

        Public Sub New()
            For Each family In Fonts.SystemFontFamilies
                _fontFamilies.Add(New FontFamilyListItemViewModel(family))
            Next

            For Each size In CommonlyUsedFontSizes
                _fontSizes.Add(size)
            Next

            _fontFamiliesView = CollectionViewSource.GetDefaultView(FontFamilies)
            _fontSizesView = CollectionViewSource.GetDefaultView(FontSizes)
        End Sub

        Private _fontFamilies As New ObjectModel.ObservableCollection(Of FontFamilyListItemViewModel)
        Public ReadOnly Property FontFamilies() As ObjectModel.ObservableCollection(Of FontFamilyListItemViewModel)
            Get
                Return _fontFamilies
            End Get
        End Property

        Private _fontFamiliesView As ICollectionView
        Public ReadOnly Property FontFamiliesView() As ICollectionView
            Get
                Return _fontFamiliesView
            End Get
        End Property

        Public ReadOnly Property SelectedFontFamily() As FontFamily
            Get
                If FontFamiliesView.CurrentItem Is Nothing Then
                    Return Nothing
                End If
                Dim fontFamilyListItem = DirectCast(FontFamiliesView.CurrentItem, FontFamilyListItemViewModel)
                Return fontFamilyListItem.FontFamily
            End Get
        End Property


        Private Shared ReadOnly CommonlyUsedFontSizes() As Double = New Double() { _
            3.0, 4.0, 5.0, 6.0, 6.5, _
            7.0, 7.5, 8.0, 8.5, 9.0, _
            9.5, 10.0, 10.5, 11.0, 11.5, _
            12.0, 12.5, 13.0, 13.5, 14.0, _
            15.0, 16.0, 17.0, 18.0, 19.0, _
            20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0, 34.0, 36.0, 38.0}

        Private _fontSizes As New ObjectModel.ObservableCollection(Of Double)
        Public ReadOnly Property FontSizes() As ObjectModel.ObservableCollection(Of Double)
            Get
                Return _fontSizes
            End Get
        End Property


        Private _fontSizesView As ICollectionView
        Public ReadOnly Property FontSizesView() As ICollectionView
            Get
                Return _fontSizesView
            End Get
        End Property

        Public ReadOnly Property SelectedFontSize() As Double
            Get
                If FontSizesView.CurrentItem Is Nothing Then
                    Return 10.5
                End If
                Dim fontSize = DirectCast(FontSizesView.CurrentItem, Double)
                Return fontSize
            End Get
        End Property


    End Class


End Namespace
